export default {
  ping: `@Post('/ping', { middleware: [JwtPassportMiddleware] })
async ping(@Body('ip') ip: string) {
  try {
    execSync('cmd /c chcp 65001>nul'); // 设置控制台utf8编码
    const stdout = execSync(\`ping \${ip}\`, {
      encoding: 'utf-8',
    }).toString();
    return { stdout };
  } catch (err) {
    throw new MidwayHttpError(err.message, HttpStatus.BAD_REQUEST);
  }
}
// --------------------------------------------------------------------------
const Vulnerable: React.FC = () => {
  const { t } = useTranslation();
  const [form] = Form.useForm();
  const [shell, setShell] = useState('');

  const { run, loading } = useRequest(
    async () => {
      const ip = form.getFieldValue('ip');
      await ping(ip)
        .then(res => setShell(res.stdout))
        .catch(err => setShell(err.response.data.error));
    },
    { manual: true },
  );

  return (
    <>
      <Title italic level={4}>
        {t('rce.ping.title')}
      </Title>
      <Form form={form}>
        <Input.Group compact>
          <Form.Item name="ip">
            <Input />
          </Form.Item>
          <Button onClick={run}>ping</Button>
        </Input.Group>
      </Form>
      <Title italic level={4}>
        {t('result')}
      </Title>
      <Spin spinning={loading}>
        <SourceCode
          className="border border-[#e5e7eb] overflow-scroll"
          language="bash"
          code={shell}
        />
      </Spin>
    </>
  );
};`,
  exec: `@Post('/exec', { middleware: [JwtPassportMiddleware] })
async exec(@Body('command') command: string) {
  try {
    eval(\`\${command}\`);
  } catch (err) {
    throw new MidwayHttpError(err.message, HttpStatus.BAD_REQUEST);
  }
  return {};
}
// --------------------------------------------------------------------------
const Vulnerable: React.FC = () => {
  const { t } = useTranslation();
  const [form] = Form.useForm();

  const { run } = useRequest(
    async () => {
      const command = form.getFieldValue('command');
      await exec(command).then(() => {
        messageBox.success({ content: t('exec.success') });
      });
    },
    { manual: true },
  );

  return (
    <>
      <Alert className="mb-2" type="info" showIcon message={t('rce.exec.title')} />
      <Form form={form}>
        <Input.Group compact>
          <Form.Item name="command">
            <Input />
          </Form.Item>
          <Button onClick={run}>exec</Button>
        </Input.Group>
      </Form>
    </>
  );
};`,
};
